//index.js
//获取应用实例
const app = getApp();

Page({
    data: {
        radioList: [
            {name: '投诉', value: 1},
            {name: '建议', value: 2},
        ],
        valueCurry: 1,
        orderId: 0,
        image: ''
    },
    onLoad: function (options) {
        console.log(options);
        if(typeof options.order_id != 'undefined') {
            this.setData({
                orderId: options.order_id
            })
        }
    },
    onHide: function () {
    },
    onChange: function (e) {
        let $dataset = e.currentTarget.dataset;
        this.setData({
            valueCurry: $dataset.index
        })
    },

    uploadfile: function () {
        var _this = this;
        wx.chooseImage({
            count: 1,
            success: function (res) {
                var tempFilePaths = res.tempFilePaths
                wx.uploadFile({
                    url: app.api.url.nosign.fileUpload,
                    filePath: tempFilePaths[0],
                    name: 'file',
                    formData: {
                        name: 'file'
                    },
                    success: function (res) {
                        var data = JSON.parse(res.data)
                        _this.setData({
                            image: data.data.url
                        })
                    }
                })
            }
        })
    },
    submit: function (e) {
        
        var data = e.detail.value;
        data.type = this.data.valueCurry;
        data.image = this.data.image;
        
        var orderId = this.data.orderId;
        var url = app.api.url.user.feedback
        
        if(orderId > 0) {
            url = app.api.url.order.feedback;
            data.order_id = orderId;
        }
        
        var object = {
            url: url,
            data: data,
        }

        const success = res =>{

            if (res.status == 1) {
                app.showModal('提示', '提交成功', false, function () {
                    app.navigateBack();
                })
            } else {
                app.showToast(res.info);
            }
        }

        app.request(object).then(success);
    }
});
